import mountDialog from "./utils/mount";
import removeDom from "./utils/removeDom";
class Dialog {
  dialogOptions = {
    domId: "",
    style: {},
    name: "",
  };
  
  constructor(name = "dialog") {
    this.domIdList = [];
    this.dialogOptions.name = name;
  }
  //传入参数1: 要向挂在组件传入的值。传入参数2:传入的指定id，非必选，可传入
  showDialog = (option, domId) => {
    if(option.isSingle){
      this.closeAll()
    }
    console.log(this.domIdList)
    this.dialogOptions.domId = domId
      ? domId
      : this.dialogOptions.name + this.domIdList.length + new Date().getTime();
    this.domIdList.push(this.dialogOptions.domId);
    console.log(this.domIdList)
    mountDialog(JSON.parse(JSON.stringify(this.dialogOptions)), option);
  }
  // 关闭所有弹窗
  closeAll = () => {
    console.log(this.domIdList)
    this.domIdList.forEach((domId) => {
      removeDom(domId);
    });
    this.domIdLis = [];
  }
  // 关闭指定弹窗
  close = (domId) => {
    removeDom(domId);
  }
  get dialogOptions() {
    return this.dialogOptions;
  }
}
export default Dialog;
